<style type="text/css">
.page_tree li .ie_fix {width: 100%;}
.page_edit_delete {width: 135px; text-align: right;margin-right: 5px;}
.page_tree {padding: 5px; border: 1px solid #cccccc; background-color: #F4F5F7;}
.page_tree li.disabled span.disabled {color: #cccccc; cursor: default;}
.page_tree li.disabled .page_edit_delete {display: none;}
h2 img {vertical-align: middle;}
h2 span {margin-right: 10px;}
.disable-delete .page_delete {display: none;}
</style>
<?php
if (count($containers))
{
    $itemTemplate = '<li class="sortable" id="{id}">
    <div class="ie_fix sort-handle">
        {content}
        <div class="page_edit_delete">
            '.CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/page/duplicate.png', 'Duplicate', array('width'=>23,'height'=>29)), array('/Core/service/ajax', 'SID'=>'Cms.pageWidget.duplicateData'), array('class'=>'duplicate', 'title'=>'Duplicate')).'
            '.CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/page/change_layout.png', 'Change Layout', array('width'=>23,'height'=>29)), array('/Cms/admin/pageWidget/layout', 'layout'=>'popup'), array('class'=>'change_layout', 'title'=>'Change Layout')).'
            '.CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/page/add_new.png', 'Add Widget', array('width'=>23,'height'=>29)), array('/Cms/admin/pageWidget/create', 'layout'=>'popup'), array('class'=>'add_widget', 'title'=>'Add Widget')).'
            '.CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/page/page_edit.png', 'Edit Widget', array('width'=>23,'height'=>29)), array('/Cms/admin/widget/updateInstance'), array('class'=>'sub_page', 'title'=>'Edit Widget')).'
            '.CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/page/page_delete.png', 'Remove Widget', array('width'=>23,'height'=>29)), '#', array('class'=>'page_delete', 'title'=>'Are you sure you want to remove?')).'
        </div>
    </div>
</li>';
//    var_dump($containers);exit;
    foreach ($containers as $container => $items)
    {
        if (!is_array($items) || (is_array($items) && count($items) <= 0))
            $items = array('<div class="empty"></div>');
        
        echo '<h2><span>'.$container.'</span>'.CHtml::link(CHtml::image(Yii::app()->theme->baseUrl.'/images/page/add_new.png', 'Add Widget', array('width'=>23,'height'=>29)), array('/Cms/admin/pageWidget/create', 'page_id'=>$model->page_id, 'revision_id'=>$model->id, 'container'=>$container, 'layout'=>$this->get('layout', '')), array('title'=>'Add Widget')).'</h2>';
        $this->widget('zii.widgets.jui.CJuiSortable', array(
            'id'=>'list-container-'.$container,
            'items'=>$items,
            'itemTemplate'=>$itemTemplate,
            'htmlOptions'=>array('class'=>'page_tree connectedSortable'),
            'options'=>array(
                'connectWith'=>'.connectedSortable',
                'update'=>'js:jQuery.fn.updateContainer',
                'cancel'=>'.disabled',
            ),
        ));
    }
}
?>